package pimp.organizermanager;

import java.util.*;

public abstract class OurCalendar {
    public abstract Map<ID, GlobalEvent> getGlobalEventByDate(Date beginDate,
            Date endDate);
    public abstract Map<ID, GlobalEvent> getGlobalEventByDate(Date beginDate,
            Date endDate, ID id);

    static public boolean calculateDate(Date date) {
        int year = date.getThisYear();
        int month = date.getThisMonth();
        int day = date.getThisDay();

        if(month <= 7 && month % 2 == 1) {
            if(day > 31) {
                return false;
            }
        }
        else if(month <= 7 && month % 2 == 0) {
            if(month == 2) {
                if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                    if(day > 29) {
                        return false;
                    }
                }
                else {
                    if(day > 28) {
                        return false;
                    }
                }
            }
            else {
                if(day > 30) {
                    return false;
                }
            }
        }
        if(month > 7 && month % 2 == 0) {
            if(day > 31) {
                return false;
            }
        }
        else if(month > 7 && month % 2 == 1) {
            if(day > 30) {
                return false;
            }
        }
        return true;
    }

    static public int calculateDaysInMonth(int year, int month) {
        int result = 0;
        if(month <= 7 && month % 2 == 1) {
            result = 31;
        }
        else if(month <= 7 && month % 2 == 0) {
            if(month == 2) {
                if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                    result = 29;
                }
                else {
                    result = 28;
                }
            }
            else {
                result = 30;
            }
        }
        if(month > 7 && month % 2 == 0) {
            result = 31;
        }
        else if(month > 7 && month % 2 == 1) {
            result = 30;
        }
        return result;
    }

}
